package com.example.fileserver_API.utils;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class GetDateUtils {
    /**
     * 获取当前月的所有日期
     * @return List<LocalDate>
     */
    public static List<String> GetAllDate(){
        LocalDate today = LocalDate.now();
        LocalDate firstDayOfMonth = today.withDayOfMonth(1);
        LocalDate lastDayOfMonth = today.withDayOfMonth(today.lengthOfMonth());
        List<String> dataall = new ArrayList<>();
        for (LocalDate date = firstDayOfMonth; !date.isAfter(lastDayOfMonth); date = date.plusDays(1)) {
            dataall.add(date.toString());
        }
        return dataall;
    }

    /**
     * 获取当前星期的所有日期
     * 星期一~星期五
     * @return List<String>
     */
    public static List<String> GetWeekDate(){
        LocalDate today = LocalDate.now(); // 获取当前日期
        List<String> weekDates = new ArrayList<>(); // 存储一周的日期
        for (int i = 0; i < 7; i++) {
            LocalDate item = today.minusDays(i);
            weekDates.add(item.toString());
        }
        // 将列表转换为数组
        String[] weekDatesArray = weekDates.toArray(new String[0]);
        // 对数组进行排序
        Arrays.sort(weekDatesArray);
        // 将排序后的数组转换回列表
        weekDates = Arrays.asList(weekDatesArray);
        return weekDates;
    }
}
